package com.qpcy.controller;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.qpcy.dto.CasesDto;
import com.qpcy.entity.Cases;
import com.qpcy.entity.Product;
import com.qpcy.service.CasesService;
import com.qpcy.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import static com.qpcy.entity.table.CasesTableDef.CASES;


/**
 * 案例 控制层。
 *
 * @author LENOVO
 * @since 2024-10-19
 */
@RestController
@RequestMapping("/cases")
public class CasesController {

    @Autowired
    private CasesService casesService;

    /**
     * 获取案例列表
     *
     * @param styleId
     * @return
     */
    @GetMapping("/list")
    public ResponseResult list(int styleId) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(CASES.STYLE_ID.eq(styleId))
                .orderBy(CASES.SORT.asc());
        return ResponseResult.success(casesService.list(queryWrapper));
    }

    /**
     *
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getAll")
    public ResponseResult getAll(int page, int size) {
        return casesService.getAll(page, size);
    }

    /**
     * 获取案例详情
     *
     * @param casesId
     * @return
     */
    @GetMapping("/detail")
    public ResponseResult getDetail(int casesId) {
        return casesService.getDetail(casesId);
    }

    /**
     * 保存案例
     *
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CasesDto dto) {
        return casesService.saveCases(dto);
    }

    /**
     * 更新案例
     *
     * @param dto
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody CasesDto dto) {
        return casesService.updateCases(dto);
    }

    /**
     * 删除案例
     *
     * @param casesId
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult delete(int casesId) {
        return ResponseResult.success(casesService.removeById(casesId));
    }


}
